// pages/map/map.js
const app = getApp()
Page({
  data: {
    longitude: '',
    latitude: '',
    markers: [],
    controls: [
      {
        id: 1,
        iconPath: '../../images/map.png',
        position: {
          left: (app.globalData.windowWidth / 2) - 14,
          top: ((app.globalData.windowHeight - 36) / 2) - 7,
          width: 26,
          height: 30
        },
        clickable: true
      },
      {
        id: 2,
        iconPath: '../../images/center.png',
        position: {
          left: 20,
          top: app.globalData.windowHeight - 90,
          width: 31,
          height: 31
        },
        clickable: true
      }
    ]
  },
  controltap() {
    this.mapCtx.moveToLocation()//将地图中心移动到当前定位点
  },
  onReady: function (e) {
    // 使用 wx.createMapContext 获取 map 上下文
    this.mapCtx = wx.createMapContext('map')
  },
  onShow() {
    this.getLocation();
    this.getMessage();
  },
  getMessage() {
    wx.request({
      url: 'http://t.yushu.im/v2/movie/top250',
      data: {},
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: this.getMessageSucc.bind(this)
    })
  },
  getMessageSucc(res) {
    // console.log(res.data)
  },
  getLocation(){
    wx.getLocation({
      type: 'gcj02',
      success: this.handleGetLocationSucc.bind(this)
    })
  },
  handleGetLocationSucc(res){
    this.setData({
      longitude: res.longitude,
      latitude: res.latitude
    })
  },
  onShareAppMessage(res) {
    return {
      title: '白熊阅读',
      path: '/pages/index/index'
    }
  }

})